var News = {
	firends: null,
	items: null,
	init: function() {
		$ajax({
			url: "/user/detail",
			data: {_id:CurrentUser._id},
			success: function(res) {
				var items = res.result.friends;
				Alist.firends = items;
				SetLS("alist", items);
				var html = "";
				var length = items && items.length || 0;
				var content = '';
				var jumpEvent = '';
				for (var i=0; i<length; ++i) {
					if (items[i].from == CurrentUser._id && items[i].status == FRIENDSTATUS.PEDDING)
						continue;
					if (items[i].status == FRIENDSTATUS.REFUSE || items[i].status == FRIENDSTATUS.REMOVE)
						continue;

					var tip = CurrentUser.category==30?"电话":"Phone" + items[i].phone;
					if (items[i].status == FRIENDSTATUS.PEDDING){
						content =   '<div class="ub upl_p5">'+
							        '    <div class="ub ub-f1 ub-ac ub-pe" ontouchstart="zy_touch()" onclick="Alist.setStatus(\''+ i +'\',\''+ FRIENDSTATUS.AGREE +'\')"><button class="upp3 ufp8 bc_green t-wh uc-a">'+CurrentUser.category==30?"接受":"Accept"+'</button></div>'+
							        '    <div class="ub ub-f1 ub-ac ub-pe upl_p5" ontouchstart="zy_touch()" onclick="Alist.setStatus(\''+ i +'\',\''+ FRIENDSTATUS.REFUSE +'\')"><button class="upp3 ufp8 uc-a">'+CurrentUser.category==30?"拒绝":"Reject"+'</button></div>'+
							        '</div>';
						tip = items[i].tip;
					} else if (items[i].status == FRIENDSTATUS.AGREE) {
						jumpEvent = "Alist.detail("+ i +")";
					}
					html += '<div class="ub up_list detailEvt" ontouchstart="zy_touch()" onclick=' + jumpEvent + '>'+
					        '    <div class="uw3 uh3 ub_img_cover detailEvt" style="background-image:url('+ Core.id2url(items[i]) +')"></div>'+
					        '    <div class="ub-f1 ub ub-ver upl_p5">'+
					        '        <div class="ub-f1 ub">'+
					        '            <div class="ub-f1 ub_left">'+ items[i].name +'　'+ (items[i].sex?items[i].sex:'') + ' '+ (items[i].country?items[i].country:'') +'</div>'+
					        '        </div>'+
					        '        <div class="ub_left ub-f1">'+ tip +'</div>'+
					        '    </div>'+ 
					        content + 
					        '</div>';
				}
				$("#ctn").html(html);
			}
		});
	},
	setStatus: function(pos,status){
		var item = Alist.firends[pos];
		var $this = $(event.currentTarget);
		$ajax({
			url: "/user/updateFriend",
			data: {
				_id: CurrentUser._id,
				friendId: item.id,
				status: status
			},
			success: function(res){
				if (status == FRIENDSTATUS.AGREE){
					$this.parent().parent(".detailEvt").attr("onclick","Alist.detail("+ pos +")");
					$this.parent().remove();
				}
				else if (status == FRIENDSTATUS.REFUSE)
					$this.parent().parent().remove();
			}
		});
	},
	detail: function(pos) {
		var alistItems = GetLS("alist");
		SetLS("address_detail", alistItems[pos]);
		OpenNewWin("address_detail");
	},
	detailInit: function() {
		var friend = GetLS("address_detail");
		$("#photo").css("background-image", "url("+ Core.id2url(friend) +")");
		$("#name").text(friend.name +"　"+ (friend.sex?friend.sex:""));
		$("#phone").text(CurrentUser.category==30?"电话:"+friend.phone:"Phone:"+friend.phone);
        var wu=CurrentUser.category==30?"无":"No";
        $("#country").text(CurrentUser.category==30?"国家:"+ (friend.courntry?friend.courntry:wu):"Country:"+ (friend.courntry?friend.courntry:wu));
        $("#education").text(CurrentUser.category==30?"学历:"+ (friend.education?friend.education:wu):"Education:"+ (friend.education?friend.education:wu));
        $("#des").text(CurrentUser.category==30?"描述:"+ (friend.des?friend.des:wu):"Description:"+ (friend.des?friend.des:wu));

	},
	chat: function() {
        SetLS("alist_chat", true);
		SetLS("chat_detail", GetLS("address_detail"));
		OpenNewWin("chat_detail");
	},	
	remove: function() {
  		$confirm(CurrentUser.category==30?"确定要删除吗？":"Do you want to detete?", function(){
  			var friend = GetLS("address_detail");
  			var length = CurrentUser.friends.length;
  			$ajax({
				url: "/user/updateFriend",
				data: {
					_id: CurrentUser._id,
					friendId: friend.id,
					status: FRIENDSTATUS.REMOVE
				},
				success: function(res) {
					SetLS("user",CurrentUser);
					PCall("address", "CCall('Alist.init();')");
					WinClose();
				}
			});
  		});
	},
	jumpBigPic: function(){
        var array = new Array("http://120.25.151.61/erweima.png");
        uexImageBrowser.open(array,1);
    },  
	listInit: function(){
		$ajax({
			url: "/news/list",
			success: function(res){
				var data = res.result;
				console.log(data);
				$.each(data,function(i,item){
					var chanelId = item.chanelId;
					$("#"+chanelId).html('');
					$.each(item.news,function(j,news){
						$("#"+chanelId).append(News.getNewsHtml(news));
					});
				});
			}
		});
	},
	listInitFocus: function(){
            $ajax({
                url: "/news/fc",
                data: {
                    chanelId:"Focus"
                 },
                success: function(res) {
                    var arr = res.result;
                    $("#Focus1").html('');
                    $.each(arr,function(j,news){
                        $("#Focus1").append(News.getNewsHtml(news));
                    });
                }
            });
    },
    
    listInitCulture: function(){
            $ajax({
                url: "/news/cl",
                data: {
                     chanelId:"Culture"
                },
                success: function(res) {
                    var arr = res.result;
                    $("#Culture1").html('');
                    $.each(arr,function(j,news){
                        $("#Culture1").append(News.getNewsHtml(news));
                    });
                }
            });
    },
    
    listInitTravel: function(){
            $ajax({
                url: "/news/tr",
                data: {
                     chanelId:"Travel"
                },
                success: function(res) {
                    var arr = res.result;
                    $("#Travel1").html('');
                    $.each(arr,function(j,news){
                        $("#Travel1").append(News.getNewsHtml(news));
                    });
                }
            });
    },
    
    listInitSports: function(){
            $ajax({
                url: "/news/sp",
                data: {
                     chanelId:"Sports"
                },
                success: function(res) {
                    var arr = res.result;
                    $("#Sports1").html('');
                    $.each(arr,function(j,news){
                        $("#Sports1").append(News.getNewsHtml(news));
                    });
                }
            });
    },
    
    listInitBusiness: function(){
            $ajax({
                url: "/news/bu",
                data: {
                     chanelId:"Business"
                },
                success: function(res) {
                    var arr = res.result;
                    $("#Business1").html('');
                    $.each(arr,function(j,news){
                        $("#Business1").append(News.getNewsHtml(news));
                    });
                }
            });
    },
    
    listInitWorld: function(){
            $ajax({
                url: "/news/wo",
                data: {
                     chanelId:"World"
                },
                success: function(res) {
                    var arr = res.result;
                    $("#World1").html('');
                    $.each(arr,function(j,news){
                        $("#World1").append(News.getNewsHtml(news));
                    });
                }
            });
    },
    
     listInitLifestyle: function(){
            $ajax({
                url: "/news/li",
                data: {
                     chanelId:"Lifestyle"
                },
                success: function(res) {
                    var arr = res.result;
                    $("#Lifestyle1").html('');
                    $.each(arr,function(j,news){
                        $("#Lifestyle1").append(News.getNewsHtml(news));
                    });
                }
            });
    },
    
	getNewsHtml: function(item){
	    var scouce=item.source;
	    //var scouce=sc.split(".");
	    //var sj=(new Date((item.create?item.create:new Date()))).pattern('yyyy-MM-dd HH:mm');
	    //var time=sj.split("-");
	    var time = item.create;
	    var view=item.view;
	    if(view==undefined){
	        view=0;
	    }
	    //$alert(uexWidgetOne.platformName);
	    if (uexWidgetOne.platformName == "android") {
            var tt=item.title;
            var title=tt.substring(0,45);
            var cc=title.length;
            if(cc < 45){
               title=title;  
            }else{
                title=title+"...";
            }
    		var html = '<div class="ub ub-f1 ub-ver">' + 
                       '     <div class="ub ub-ac up_list upp2" ontouchstart="zy_touch()" onclick="News.jumpDetail(\'' + item._id + '\',\'' + item.chanelId + '\')">' + 
                       '         <div class="ub-img1 uw6w5 uh5p5 umt_p2 umb_p5 uml_p2" style="background-image:url(\'' + Core.NEW_IMG+item.pic + '\')"></div>' + 
                       '         <div class="ub ub-ver ubb b_gra upp2 ub-f1">' + 
                       '             <div class="ub" >' + 
                       '                <div class="ub-f1 umt_2f3f upl_p5 uf1p3 ub ub-ac wb_c" style="text-overflow: ellipsis;-webkit-box-align: start; -webkit-box-pack: start;-webkit-line-clamp: 2;" id="ctt">' + title + '</div>' + 
                       '             </div>' + 
                       '         <div class="ub umt_1p2 uml_p2 pso_abs">'+
                       '             <div class="gray3 ut-c uf1p1f pso_abs upl_p5">' + scouce + '</div>'+
                       '             <div class="gray3 ut-c uf1p1f uml_8l5 pso_abs">'+view+'views</div>' + 
                       '             <div class="ub gray3 ut-c uf1p1f ub_right ub-f1 uml_15 pso_abs">' + time + '</div>'+
                       '         </div>' + 
                       '     </div>' + 
                       '   </div>'+
                       '</div>';
            return html; 
        }else if (uexWidgetOne.platformName == "iOS") {
            var tt=item.title;
            var title=tt.substring(0,50);
            var cc=title.length;
            if(cc < 50){
               title=title;  
            }else{
                title=title+"...";
            }
            var w=$(window).width();
              if(w <= 750){
                   var html =  '<div class="ub ub-f1 ub-ver">' + 
                               '     <div class="ub ub-ac up_list upp2" ontouchstart="zy_touch()" onclick="News.jumpDetail(\'' + item._id + '\',\'' + item.chanelId + '\')">' + 
                               '         <div class="ub-img1 uw6w5 uh5p5 umt_p2 umb_p5 uml_p2" style="background-image:url(\'' + Core.NEW_IMG+item.pic + '\')"></div>' + 
                               '         <div class="ub ub-ver ubb b_gra upp2 ub-f1">' + 
                               '             <div class="ub" >' + 
                               '                <div class="ub-f1 umt_2f upl_p5 uf1p3 ub ub-ac wb_c" style=" text-overflow: ellipsis;-webkit-box-pack: start;-webkit-box-align: start; -webkit-line-clamp: 2;" id="ctt">' + title + '</div>' + 
                               '             </div>' + 
                               '         <div class="ub umt_1p2 uml_p2 pso_abs">'+
                               '             <div class="gray3 ut-c uf1p1f pso_abs upl_p5">' + scouce + '</div>'+
                               '             <div class="gray3 ut-c uf1p1f uml_8l5 pso_abs">'+view+'views</div>' + 
                               '             <div class="ub gray3 ut-c uf1p1f ub_right ub-f1 uml_16 pso_abs">' + time + '</div>'+
                               '         </div>' + 
                               '     </div>' + 
                               '   </div>'+
                               '</div>';
                    return html;  
              }else{
                   var html =  '<div class="ub ub-f1 ub-ver">' + 
                               '     <div class="ub ub-ac up_list upp2" ontouchstart="zy_touch()" onclick="News.jumpDetail(\'' + item._id + '\',\'' + item.chanelId + '\')">' + 
                               '         <div class="ub-img1 uw6w5 uh5p5 umt_p2 umb_p5 uml_p2" style="background-image:url(\'' + Core.NEW_IMG+item.pic + '\')"></div>' + 
                               '         <div class="ub ub-ver ubb b_gra upp2 ub-f1">' + 
                               '             <div class="ub">' + 
                               '                <div class="ub-f1 umt_2f upl_p5 uf1p4 ub ub-ac wb_c" style=" text-overflow: ellipsis;-webkit-box-pack: start;-webkit-box-align: start; -webkit-box-orient: vertical;-webkit-line-clamp: 2;" id="ctt">' + title + '</div>' + 
                               '             </div>' + 
                               '         <div class="ub umt_1p2 uml_p2 pso_abs">'+
                               '             <div class="gray3 ut-c uf1p2 pso_abs upl_p5">' + scouce + '</div>'+
                               '             <div class="gray3 ut-c uf1p2 uml_12 pso_abs">'+view+'views</div>' + 
                               '             <div class="gray3 ut-c uf1p2 ub_right ub-f1 uml_17 pso_abs">' + time + '</div>'+
                               '         </div>' + 
                               '     </div>' + 
                               '   </div>'+
                               '</div>';
                        return html;  
              }
             
            }else{
                var tt=item.title;
                var title=tt.substring(0,45);
                var cc=title.length;
                if(cc < 45){
                   title=title;  
                }else{
                    title=title+"...";
                }
               var w=$(window).width();
               if(w <= 750){
                   var html = '<div class="ub ub-f1 ub-ver">' + 
                       '     <div class="ub ub-ac up_list upp2" ontouchstart="zy_touch()" onclick="News.jumpDetail(\'' + item._id + '\',\'' + item.chanelId + '\')">' + 
                       '         <div class="ub-img1 uw6w5 uh5p5 umt_p2 umb_p5 uml_p2" style="background-image:url(\'' + Core.NEW_IMG+item.pic + '\')"></div>' + 
                       '         <div class="ub ub-ver ubb b_gra upp2 ub-f1">' + 
                       '                <div class="ub ub-f1 umt_2f6 upl_p5 uf1p1 ub ub-ac wb_c" style=" text-overflow: ellipsis;-webkit-box-pack: start;-webkit-box-align: start; -webkit-line-clamp: 2;" id="ctt">' + title + '</div>' + 
                       '         <div class="ub umt_1p2 uml_p2 pso_abs">'+
                       '             <div class="gray3 ut-c uf1p1f pso_abs upl_p5">' + scouce + '</div>'+
                       '             <div class="gray3 ut-c uf1p1f uml_7 pso_abs">'+view+'views</div>' + 
                       '             <div class="gray3 ut-c uf1p1f ub_right ub-f1 uml_12 pso_abs">' + time + '</div>'+
                       '         </div>' + 
                       '     </div>' + 
                       '   </div>'+
                       '</div>';
            return html;    
               }else{
                    var html = '<div class="ub ub-f1 ub-ver">' + 
                       '     <div class="ub ub-ac up_list upp2" ontouchstart="zy_touch()" onclick="News.jumpDetail(\'' + item._id + '\',\'' + item.chanelId + '\')">' + 
                       '         <div class="ub-img1 uw6w5 uh5p5 umt_p2 umb_p5 uml_p2" style="background-image:url(\'' + Core.NEW_IMG+item.pic + '\')"></div>' + 
                       '         <div class="ub ub-ver ubb b_gra upp2 ub-f1">' + 
                       '                <div class="ub ub-f1 umt_2f6 upl_p5 uf1p1 ub ub-ac wb_c" style=" text-overflow: ellipsis;-webkit-box-pack: start;-webkit-box-align: start; -webkit-line-clamp: 2;" id="ctt">' + title + '</div>' + 
                       '         <div class="ub umt_1p2 uml_p2 pso_abs">'+
                       '             <div class="gray3 ut-c uf1p1f pso_abs upl_p5">' + scouce + '</div>'+
                       '             <div class="gray3 ut-c uf1p1f uml_7 pso_abs">'+view+'views</div>' + 
                       '             <div class="gray3 ut-c uf1p1f ub_right ub-f1 uml_12 pso_abs">' + time + '</div>'+
                       '         </div>' + 
                       '     </div>' + 
                       '   </div>'+
                       '</div>';
            return html;   
               }
             
            }         
	},
	jumpDetail: function(_id,chanelId){
		SetLS("news_item",{"_id":_id,"chanelId":chanelId});
		OpenNewWin("news_detail");
	},
	detailInit: function(){
		var item = GetLS("news_item");
		$ajax({
			url: "/news/detail",
			data:{
				_id: item._id
			},
			success: function(res){
				var data = res.result;
				$(".value").each(function(){
					$(this).html(data[$(this).attr("id")]);
				});
				$("#photoList").html('<div class="uw99 umauto uptb_p5 photo"><img src="' + Core.NEW_IMG+data.pic + '" class="uw100"></div>');
			    if(uexWidgetOne.platformName == "iOS"){
                   $("p").css("margin","0px 20px 6.5px 15px");  
                }else if (uexWidgetOne.platformName == "android") {
                   $("p").css("margin","26px"); 
                }else{
                   $("p").css("margin","0px 20px 6.5px 15px");  
                } 
        	}
		});
	}
}